<style type="text/css">
    .layui-card .layui-field-box{margin-left: 0}
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称</label>
                <div class="layui-input-block">
                    <input type="text" name="gname" lay-verify="required" class="layui-input"
                           placeholder="角色名称" <{if isset($data)}>value="<{$data->gname}>"<{/if}> autocomplete="off">
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-header">选择权限</div>
                <div class="layui-card-body">
                    <div class="layui-tab " lay-filter="component-tabs-brief">
                        <ul class="layui-tab-title">
                            <{foreach $allrights as $item}>
                            <li class="<{if $item@first }>layui-this<{/if}>"> <{$item.name}></li>
                            <{/foreach}>
                        </ul>
                        <div class="layui-tab-content">
                            <{foreach $allrights as $item}>
                            <div class="layui-tab-item <{if $item@first }>layui-show<{/if}>">
                                <{if $item.children}>
                                <{foreach $item.children as $child}>
                                <{if $child.children}>
                                <fieldset class="layui-elem-field">
                                    <legend><{$child.name}></legend>
                                    <div class="layui-field-box layui-input-block">
                                        <{foreach $child.children as $child2}>
                                        <input type="checkbox" name="rights[]" <{if isset($groupRight) and
                                        in_array($child2.id,$groupRight)}>checked="checked"<{/if}>
                                        value="<{$child2.id}>" lay-skin="primary" title="<{$child2.name}>" />
                                        <{/foreach}>
                                    </div>
                                </fieldset>
                                <{else}>
                                <fieldset class="layui-elem-field">
                                    <legend><{$child.name}></legend>
                                    <div class="layui-field-box">
                                        <input type="checkbox" name="rights[]"
                                        <{if isset($groupRight) and
                                        in_array($child.id,$groupRight)}>checked="checked"<{/if}>
                                        value="<{$child.id}>" lay-skin="primary" title="<{$child.name}>" />
                                    </div>
                                </fieldset>
                                <{/if}>
                                <{/foreach}>
                                <{else}>
                                <fieldset class="layui-elem-field">
                                    <legend><{$item.name}></legend>
                                    <div class="layui-field-box">
                                        <input type="checkbox" name="rights[]"
                                        <{if isset($groupRight) and
                                        in_array($item.id,$groupRight)}>checked="checked"<{/if}>
                                        value="<{$item.id}>" lay-skin="primary" title="<{$item.name}>" />
                                    </div>
                                </fieldset>
                                <{/if}>
                            </div>
                            <{/foreach}>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="form-submit" id="form-submit"
                       value="确认添加">
            </div>
        </form>
    </div>
</div>
<script>

    layui.use(['form', 'element'], function () {
        var $ = layui.$
            , form = layui.form
            , element = layui.element;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/gid/<{if isset($data)}><{$data->gid}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    layui.table.reload('table-page'); //重载表格
                    layer.close(parentIndex);
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>